package day10;

/**
 * @author oldliu
 * @since 1.0
 */
//join
public class Thread6 extends Thread {

    public Thread6(String n) {
        super(n);
    }

    public void run() {
        for (int i = 1; i <= 20; i++) {
            System.out.println(this.getName() + " 打印了 " + i);
            super.yield();
        }
    }

    public static void main(String[] args) {
//        for (int i = 1; i <= 4; i++) {
//            //子线程4个+1个main
//            new Thread6("线程 " + i).start();
//
//        }
        //join 所有的线程启动完成后，再join
        Thread th[]=new Thread[6];
        for(int i=0;i<th.length;i++){
            th[i]=new Thread6("线程 " + i);
            th[i].start();
        }
        //主线程等待这六个执行完
        for(int i=0;i<th.length;i++){
            try {
                th[i].join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("主线程结束了。。。");
    }
}
